﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eCitizen.DataContracts;

namespace eCitizen.DataAccess
{
    public class ConfigurationService : dbService
    {
        public List<SftpConfiguration> LoadConfigurations()
        {
            List<SftpConfiguration> configurationList = new List<SftpConfiguration>();

            SqlConnection dbConnection = new SqlConnection(ecitizenPersonalisedDBConnString);

            dbConnection.Open();

            SqlCommand dbCommand = new SqlCommand();
            IDataReader dbReader = null;


            dbCommand.Connection = dbConnection;
            dbCommand.CommandText = "eCitizen_Personalised.usp_GetSupportedServices";
            dbCommand.CommandType = CommandType.StoredProcedure;

            dbReader = dbCommand.ExecuteReader();

            while (dbReader.Read())
            {
                SftpConfiguration configurationItem = new SftpConfiguration();

                configurationItem.Agency = dbReader.GetString(dbReader.GetOrdinal("Agency"));
                configurationItem.Service = dbReader.GetString(dbReader.GetOrdinal("AgencyCode"));

                configurationList.Add(configurationItem);
            }

            dbReader.Close();
            dbConnection.Close();

            return configurationList;

        }
    }
}
